package com.tiles.controller;

import com.tiles.tools.MsgUtil;
import com.tiles.tools.UploadUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

@Controller
public class UploadController {
    @RequestMapping("/img")
    @ResponseBody
    public MsgUtil uploadImg(@RequestParam("file") MultipartFile filter,HttpServletResponse response,HttpServletRequest request) {
        MsgUtil msgUtil = new MsgUtil();
            UploadUtil uploadUtil = new UploadUtil();
            String upload = uploadUtil.upload(filter);
            msgUtil.msg = upload;

        return msgUtil;
    }

    @RequestMapping("/imgUrl")
    @ResponseBody
    public MsgUtil upload(String fName,String imgUrl){
        MsgUtil msgUtil = new MsgUtil();
        System.out.println(fName);
        System.out.println(imgUrl);
        
        return new MsgUtil("ok", 0, null);
    }


}
